package net.devask.mathml.client;

import org.gwtwidgets.client.ext.ExtDOM;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MathML implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
    final Button button = new Button("Click me");
    //final Label label = new Label();
    final MathMLWidget ml = new MathMLWidget();

    button.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        /*if (label.getText().equals(""))
          label.setText("Hello World!");
        else
          label.setText("");*/
        final Element mfrac = ExtDOM.createElementNS(ml.getNamespace(), "mfrac");
        final Element mia = ExtDOM.createElementNS(ml.getNamespace(), "mi");
        DOM.setInnerText(mia, "a");
        DOM.appendChild(mfrac, mia);
        final Element mib = ExtDOM.createElementNS(ml.getNamespace(), "mi");
        DOM.setInnerText(mib, "b");
        DOM.appendChild(mfrac, mib);
        DOM.appendChild(ml.getElement(), mfrac);
      }
    });

    /* Assume that the host HTML has elements defined whose
     * IDs are "slot1", "slot2". You must be careful to ensure
     * that all IDs are unique if you use this approach.
     */
    RootPanel.get("slot1").add(button);
    //RootPanel.get("slot2").add(label);
    RootPanel.get("slot2").add(ml);
  }
}
